﻿#region Using Directives

using System;
using GoldParser;
using System.Drawing;
using System.Xml.Serialization;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;

#endregion

namespace Licenta1
{
    [Serializable]
    public class Shape:Expression
    {
           
        public Shape(Context con):base(con)
        {
        }

        public Shape()
        { }

        public virtual void Draw()
        {   
        }

        public virtual string Display()
        {
            return " \n";
        }

        public override object Value
        {
            get { return null; }
        }

        public virtual object GetClone()
        {
            return null;
        } 

        public object Copy(Type source, object sourceToCopy, Type destination)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(source);
                MemoryStream memoryStream = new MemoryStream();

                XmlSerializerNamespaces nameSpacesList = new XmlSerializerNamespaces();
                nameSpacesList.Add("", "");

                serializer.Serialize(memoryStream, sourceToCopy, nameSpacesList);

                byte[] byteArr = memoryStream.ToArray();
                ASCIIEncoding encoder = new ASCIIEncoding();
                string xmlString = encoder.GetString(byteArr);

                ASCIIEncoding newEncoder = new ASCIIEncoding();
                byte[] newByteArr = newEncoder.GetBytes(xmlString);
                MemoryStream newMemoryStream = new MemoryStream(newByteArr);

                XmlSerializer deSer = new XmlSerializer(destination);

                object deserializedObject = deSer.Deserialize(newMemoryStream);

                return deserializedObject;
            }
            catch (Exception e)
            { Console.WriteLine("e:" + e); return null; }
        }
    }
}